package cn.iocoder.yudao.module.lowcode.dal.mysql.datasource;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.lowcode.controller.admin.datasource.vo.LowcodeDataSourceConfigPageReqVO;
import cn.iocoder.yudao.module.lowcode.dal.dataobject.datasource.LowcodeDataSourceConfigDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 低代码数据源配置 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface LowcodeDataSourceConfigMapper extends BaseMapperX<LowcodeDataSourceConfigDO> {

    default PageResult<LowcodeDataSourceConfigDO> selectPage(LowcodeDataSourceConfigPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<LowcodeDataSourceConfigDO>()
                .likeIfPresent(LowcodeDataSourceConfigDO::getName, reqVO.getName())
                .eqIfPresent(LowcodeDataSourceConfigDO::getType, reqVO.getType())
                .eqIfPresent(LowcodeDataSourceConfigDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(LowcodeDataSourceConfigDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(LowcodeDataSourceConfigDO::getId));
    }

    default List<LowcodeDataSourceConfigDO> selectEnabledList() {
        return selectList(new LambdaQueryWrapperX<LowcodeDataSourceConfigDO>()
                .eq(LowcodeDataSourceConfigDO::getStatus, 1)
                .orderByDesc(LowcodeDataSourceConfigDO::getId));
    }

    default LowcodeDataSourceConfigDO selectByName(String name) {
        return selectOne(LowcodeDataSourceConfigDO::getName, name);
    }

}